﻿namespace UnityEngine
{
    using System;
    using System.Collections;

    internal class AttributeHelperEngine
    {
        private static bool CheckIsEditorScript(System.Type klass)
        {
            while ((klass != null) && (klass != typeof(MonoBehaviour)))
            {
                if (klass.GetCustomAttributes(typeof(ExecuteInEditMode), false).Length != 0)
                {
                    return true;
                }
                klass = klass.BaseType;
            }
            return false;
        }

        private static System.Type[] GetRequiredComponents(System.Type klass)
        {
            ArrayList list = null;
            while ((klass != null) && (klass != typeof(MonoBehaviour)))
            {
                object[] customAttributes = klass.GetCustomAttributes(typeof(RequireComponent), false);
                for (int i = 0; i < customAttributes.Length; i++)
                {
                    RequireComponent component = (RequireComponent) customAttributes[i];
                    if (((list == null) && (customAttributes.Length == 1)) && (klass.BaseType == typeof(MonoBehaviour)))
                    {
                        return new System.Type[] { component.m_Type0, component.m_Type1, component.m_Type2 };
                    }
                    if (list == null)
                    {
                        list = new ArrayList();
                    }
                    if (component.m_Type0 != null)
                    {
                        list.Add(component.m_Type0);
                    }
                    if (component.m_Type1 != null)
                    {
                        list.Add(component.m_Type1);
                    }
                    if (component.m_Type2 != null)
                    {
                        list.Add(component.m_Type2);
                    }
                }
                klass = klass.BaseType;
            }
            if (list == null)
            {
                return null;
            }
            return (System.Type[]) list.ToArray(typeof(System.Type));
        }
    }
}

